package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Source;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element proprietary is a metadata container of any additional metadata property that does not belong to the Akoma
 * Ntoso properties. Anything can be placed in this element.
 * 
 * <pre>
 * 	<xsd:element name="proprietary">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="anyOtherType">
 * 					<xsd:attributeGroup ref="source"/>
 *				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Proprietary extends AnyOtherType implements Source {

	public static final String ELEMENT = "proprietary";
	
	private String _source;

	/**
	 * @see org.akomantoso.core.data.attribute.Source#getSource()
	 */
	public String getSource() {
		return _source;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Source#setSource(java.lang.String)
	 */
	public void setSource(String source) {
		_source = source;
	}

	/**
	 * @see org.akomantoso.core.data.AnyOtherType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeSource(out, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.AnyOtherType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_source = in.readAttribute(Source.ATTRIBUTE);
		super.readExternal(in);
	}

}